<%--
  Created by IntelliJ IDEA.
  User: fengdefangxiang
  Date: 2022/2/9
  Time: 17:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%@ include file="/web/header.jsp" %>
    <%--    <style>--%>
    <%--        body {--%>
    <%--            /*background: aliceblue;*/--%>
    <%--            background: url(../../../img/66ef0caebea14ed09fa90a8411ba6822.jpg) no-repeat;--%>
    <%--            background-size: cover;--%>
    <%--        }--%>
    <%--    </style>--%>
</head>
<body>
<div class="window">
    <fieldset class="layui-elem-field" style="margin: 23px">

        <legend>项目添加</legend>
        <div class="layui-field-box">
            <form class="layui-form layui-form-pane">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">员工</label>
                        <div class="layui-input-inline">
                            <select name='name'></select>
                        </div>
                        <label class="layui-form-label">项目</label>
                        <div class="layui-input-inline">
                            <select name='prname'></select>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">绩效</label>
                            <div class="layui-input-inline">
                                <input type="text" name="score" required placeholder="请输入绩效"
                                       lay-verify="required" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item btn">
                            <%--                    <div class="layui-input-block">--%>
                            <input type="reset" class="layui-btn layui-btn-radius layui-btn-primary"/>
                            <input type="button" class="layui-btn layui-btn-radius" lay-submit lay-filter="add" value="确定"/>
                            <input type="button" class="layui-btn layui-btn-radius " onclick="layerclose()" value="关闭"/>
                        </div>
                        <%--                </div>--%>
                        <input type="hidden" name="action" value="add"/>
                </form>
            </form>
        </div>
    </fieldset>
</div>
<script type="text/javascript">
    initSel();
    initSel2();
    function initSel() {//从数据库初始化下拉框中的数据
        ajax('/EmployeeServlet', {action: 'list'}, 'json', function (data) {
            var opt = "<option value=''>请选择员工</option>"
            $.each(data, function () {
                opt += "<option value='" + this.code + "'>" + this.name + "</option>"
            })
            $("select[name='name']").html(opt);
            form.render()
        })
    }
    function initSel2() {
        ajax('/ProjectServlet', {action: 'list'}, 'json', function (data) {
            console.log(data)
            var opt = "<option value=''>请选择项目</option>"
            $.each(data, function () {
                opt += "<option value='" + this.code + "'>" + this.name + "</option>"
            })
            $("select[name='prname']").html(opt);
            form.render()
        })

    }
    formOnSubmit('add', '/ScoreServlet', 'text', function (data) {
        console.log(data)
        if (data == 1) {
            layer.msg("添加成功", layerclose)
        } else if (data == "repeat") {
            layer.msg("编号重复")
        } else {
            layer.msg("添加失败")
        }
    })
</script>
</body>
</html>
